<!DOCTYPE html>
<html lang="en" class="app">
<head>
<meta charset="utf-8" />
<title>管理系统</title>
<meta name="description" content="app, web app, responsive, admin dashboard, admin, flat, flat ui, ui kit, off screen nav" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <link rel="stylesheet" href="${s.base}/js/bootstrap/bootstrap.4.0.css" type="text/css" />
<link rel="stylesheet" href="${s.base}/css/app.v2.css" type="text/css" />
  <link rel="stylesheet" href="${s.base}/js/bootstrap/bootstrap-table.css" type="text/css" />
  <link rel="stylesheet" href="${s.base}/css/nestable.css" type="text/css" />
<style type="text/css">
  html,body{
    background-color: #ffffff;
  }
</style>
</head>

<body>
<section class="panel-default">
  <div class="panel-body">
    <form class="bs-example form-horizontal" action="UpdateOrAddEntity" method="post">
      <input type="hidden" class="form-control" id="departid" name="departid" value="${baseDepart.departid}" />
      <div class="form-group">
        <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;">部门名称:</label>
        <div class="col-xs-8 col-sm-offset-2">
          <input type="text" class="form-control" id="departName" name="departName" value="${baseDepart.departname}" placeholder="请输入部门名称">
        </div>
      </div>
      <div class="form-group">
        <label class="col-xs-3 control-label col-sm-offset-2" style="text-align:right;">权限:</label>
        <div class="col-xs-8 col-sm-offset-2">
          <div class="dd" id="nestable">
            <ol class="dd-list">
              <#list baseMenusListOne as baseMenuOne>
                <li class="dd-item dd3-item">

                  <input type="checkbox" value="${baseMenuOne.menuid}" <#if baseMenuOne.check>checked</#if> style="float: left;margin: 10px 0px 0px 5px;"  class="one"/>
                  <div class="dd3-content">${baseMenuOne.menuname}</div>
                  <#if baseMenuOne.childList??>
                    <ol class="dd-list" style="display: none;">
                      <#list baseMenuOne.childList as baseMenuTwo>
                        <li class="dd-item dd3-item" data-id="16">
                          <input type="checkbox" value="${baseMenuTwo.menuid}" <#if baseMenuTwo.check>checked</#if> onclick="select(this)"  class="two" style="float: left;margin: 10px 0px 0px 5px;"/>
                          <div class="dd3-content">${baseMenuTwo.menuname}</div>
                        </li>
                      </#list>
                    </ol>
                  </#if>

                </li>
              </#list>
            </ol>
          </div>
        </div>
      </div>
      <div class="line line-dashed line-lg pull-in"></div>
      <div class="form-group" >
        <div class="col-sm-12 col-sm-offset-2" style="text-align: center;">
          <button type="button" onclick="parentLayerClose()" class="btn btn-default">取消</button>
          &nbsp;&nbsp;
          <button type="button" onclick="updateOrAdd()" class="btn btn-primary">确定</button>
        </div>

      </div>
    </form>
  </div>
</section>
<script src="${s.base}/js/base/jquery-3.2.0.min.js"></script>
<script src="${s.base}/js/layer/layer.js"></script>
<script src="${s.base}/js/layer/commont.js"></script>
<script src="${s.base}/js/bootstrap/bootstrap.4.0.js"></script>
<script src="${s.base}/js/bootstrap/bootstrap-table.js"></script>
<script src="${s.base}/js/bootstrap/bootstrap-table-zh-CN.js"></script>
<script src="${s.base}/js/nestable/jquery.nestable.js" cache="false"></script>
<script src="${s.base}/js/nestable/demo.js" cache="false"></script>
<script type="text/javascript">

    /**
     * 权限选择
     * */
    $(function(){
        $('input:checkbox').click(function () {
            var type=$(this).attr("class");
            if("one"==type){
                //一级菜单
                if($(this).is(':checked')){
                    $(this).parent().find(".two").each(function (index,obj) {
                        $(obj).prop("checked","checked");
                    })
                }else{
                    $(this).parent().find(".two").each(function (index,obj) {
                        $(obj).prop("checked","");
                    })
                }
            }else if("two"==type){
                //二级菜单
                if($(this).is(':checked')){
                    var falge=true;//是否全选
                    $(this).parent().parent().find(".two").each(function (index,obj) {
                        if(!($(obj).is(':checked'))){
                            falge=false;
                        }
                    })
                    if(falge){
                        $(this).parent().parent().parent().find(".one").prop("checked","checked");
                    }
                }else{
                    $(this).parent().find(".two").each(function (index,obj) {
                        $(obj).prop("checked","");;
                    })
                    $(this).parent().parent().parent().find(".one").prop("checked","");;
                }
            }

        });
    })

    /**
  * 添加或修改
  */
 function updateOrAdd() {
     var departName=$("#departName").val();
     var departid=$("#departid").val();
        var menuIdList="";
        $('input:checkbox').each(function (index,obj) {
            if($(obj).is(':checked')){
                if(menuIdList==""){
                    menuIdList=$(obj).attr("value");
                }else{
                    menuIdList=menuIdList+","+$(obj).attr("value");
                }
            }
        })
     $.ajax({
         type: "POST",
         url: "/baseDepart/UpdateOrAddEntity",
         data: {"departid":departid,"departName":departName,"menuIdList":menuIdList},
         success: function(result){
             if(1==result.returnInfo.state){
                 parentLayerClose();
                 top.layer.msg("操作成功！");
                 layer.closeAll("iframe");
                 //刷新父页面
                 parent.location.reload();
             }else{
                 top.layer.msg(result.returnInfo.errorMsg);
             }
             /*parentLayerClose();
             if(1==result.returnInfo.state){
                 parent.showLayerAlert("操作成功");
             }else{
                 parent.showLayerAlert(result.returnInfo.errorMsg);
             }*/
         },
         error: function(result){
             parent.showLayerAlert(result);
         }
     });
 }
</script>
</body>
</html>
